package com.cc.staservice.schedule;

import com.cc.staservice.service.StatisticsDailyService;
import com.cc.staservice.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduledTask {

    @Autowired
    private StatisticsDailyService staService;

    //@Scheduled(cron = "0/5 * * * * ?")//表示每个5秒钟执行该方法
    public void task1(){
        System.out.println("task1执行了");
    }

    //每天凌晨1点，执行该方法，把前一天的数据进行查询添加
    @Scheduled(cron = "0 0 1 * * ?")
    public void task2(){
        //获取当前日期并减一
        staService.registerCount(DateUtil.formatDate(DateUtil.addDays(new Date(), -1)));
    }
}
